package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.dto.StudentQueryDto;
import com.itheima.pojo.Student;
import com.itheima.vo.StudentItemVo;
import com.itheima.vo.StudentVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface StudentMapper {
    //分页条件查询
    Page<StudentVo> query(StudentQueryDto dto);

    //删除学员
    @Delete("delete from student where id = #{id}")
    void delete(Integer id);

    //添加学员
    void insert(Student student);

    //根据ID查询
    @Select("select * from student where id = #{id}")
    Student findById(Integer id);

    //修改学员
    void update(Student student);

    //违纪处理
    void updateViolation(Integer id, Integer score);

    //学员学历统计
    List<StudentItemVo> getStudentDegreeData();

    //统计班级人数
    @Select("select c.name as name , count(s.id) as value from clazz c  left join student s on s.clazz_id = c.id group by c.name order by count(s.id) desc ")
    List<StudentItemVo> getStudentCount();

    //根据班级ID查询班级人数
    @Select("select count(*) from student where clazz_id = #{id}")
    Integer countByClazzId(Integer id);
}
